package com.example.swimmingpool.controller.goods_type;

import com.example.swimmingpool.entity.goods_type.GoodsType;
import com.example.swimmingpool.qo.goodsType.GoodsTypeQo;
import com.example.swimmingpool.response.CommonResponse;
import com.example.swimmingpool.service.goods_type.GoodsTypeService;
import com.example.swimmingpool.vo.goods_type.GoodsTypeVo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/goodsType")
public class GoodsTypeController {
    @Resource
    private GoodsTypeService goodsTypeService;

    @PostMapping("/add")
    public CommonResponse<Boolean> add(@RequestBody GoodsType goodsType) {
        var res = goodsTypeService.save(goodsType);
        return CommonResponse.success(res);
    }

    @PostMapping("/list")
    public CommonResponse<List<GoodsTypeVo>> list(@RequestBody GoodsTypeQo qo) {
        return CommonResponse.success(goodsTypeService.getGoodsTypeList(qo));
    }

    @PostMapping("/update")
    public CommonResponse<Boolean> update(@RequestBody GoodsTypeVo vo) {
        var res = goodsTypeService.update(vo);
        return CommonResponse.success(res != 0);

    }

    @PostMapping("/delete")
    public CommonResponse<Boolean> delete(@RequestBody GoodsTypeVo vo) {
        var res = goodsTypeService.removeById(vo.getId());
        return CommonResponse.success(res);

    }
}
